package org.satish.startup;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class Temp extends JPanel implements ActionListener {	
   
	private static final long serialVersionUID = 1L;
	private JFileChooser fc;

    public Temp() {
        super(new BorderLayout());

        //Create a file chooser
        fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.addActionListener(this);
        
        JPanel fileChooserPanel = new JPanel(); //use FlowLayout        
        
        fileChooserPanel.add(fc);
        this.add(fileChooserPanel);
    }

    public void actionPerformed(ActionEvent e) {
    	if(e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
    		System.out.println(fc.getSelectedFile());
    	}
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    public static void createAndShowGUI() {
    	
    	String lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
//    	String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
		try {
			UIManager.setLookAndFeel(lookAndFeel);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
        //Create and set up the window.
        JFrame frame = new JFrame("File Chooser");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation(350, 284);

        //Create and set up the content pane.
        JComponent newContentPane = new Temp();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        SwingUtilities.updateComponentTreeUI(frame);
        frame.pack();
        frame.setVisible(true);
        frame.setResizable(false);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
